


import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;

import javax.swing.JPanel;

public class BackgroundImgPanel extends JPanel {    //Panel con sfondo

        protected Image backgroundImage;

        public BackgroundImgPanel(String imgPath) {
                Toolkit tk = Toolkit.getDefaultToolkit();
                backgroundImage = tk.getImage(imgPath);
                MediaTracker mt = new MediaTracker(this);    //Attende che il caricamento sia stato completato
                mt.addImage(backgroundImage, 1);
                try { 
                        mt.waitForAll();
                }
                catch (InterruptedException e) {}
        }
        protected void paintComponent(Graphics g){
                super.paintComponent(g);
                g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), null);
        }
}